class PatientData < ActiveRecord::Base

  has_many :order_examinations
  belongs_to :sex
  belongs_to :user

  def to_label
    "#{self.first_name} #{self.laste_name}"
  end

  def planed_examinations
    OrderExamination.find_all_by_patient_data_id self.id, :conditions => { :has_resoult => false, :is_checked => false }
  end

  def first_and_last_name
    "#{self.first_name} #{self.laste_name}"
  end
  
  
  # --- Validation --- #
  validates_presence_of :first_name
  validates_presence_of :laste_name
  validates_presence_of :sex_id
  validates_presence_of :street
  validates_presence_of :street_number
  validates_presence_of :city
  validates_presence_of :zip_code
  validates_format_of :zip_code, :with => /\d{2}-\d{3}/
  validates_presence_of :email
  validates_format_of :email, :with => /\w+@\w+.\w+/
  validates_presence_of :birth_date
  validates_presence_of :telpehone_number
  validates_numericality_of :telpehone_number, :only_integer => true
  validates_length_of :telpehone_number, :is => 9
  validates_presence_of :pesel
  validates_numericality_of :pesel, :only_integer => true
  validates_length_of :pesel, :is => 11

  class << self
    HUMANIZED_ATTRIBUTE_KEY_NAMES = {
      "first_name" => "pole imie",
      "laste_name" => "pole nazwisko",
      "sex_id" => "pole płeć",
      "street" => "pole ulica",
      "street_number" => "pole numer domu",
      "city" => "pole miasto",
      "zip_code" => "pole kod pocztowy",
      "telpehone_number" => "pole numer telefonu",
      "birth_date" => "pole data urodzenia",
      "email"  => "pole adres e-mail" ,
      "pesel"  => "pole pesel" ,
    }
    def human_attribute_name(attribute_key_name)
      HUMANIZED_ATTRIBUTE_KEY_NAMES[attribute_key_name] || super
    end
end

end
